import { loadCss } from '@jsjn/utils'
// workspaace
import LGlobalComponents from '@jsjn/micro-core-components/global'
import App from '@jsjn/micro-core-views/App.vue'
import '@jsjn/micro-core-assets/styles/index.scss'
// 外部模块
import { createApp } from 'vue'
import mitt from 'mitt'
// 本地模块
import api from '@/api'
import store, { key } from '@/store'
import router from '@/router'
import directives from '@/directives'
import '@/assets/styles/index.scss'
// 组件库
import GlobalComponents, { type VeGlobalSetting } from 'jn-ve-global'
import VE_GLOBAL_CONFIG from '@jsjn/micro-core-micro-main/wujie/constants/VE_GLOBAL_CONFIG'
// element-plus
import ElementPlus from 'element-plus'
import locale from 'element-plus/es/locale/lang/zh-cn'
import 'dayjs/locale/zh-cn'
// wujie
import microInit from '@jsjn/micro-core-micro-main'

// TODO: 基座样式文件透传到子应用：主动污染子应用内 [一种优化性能的方式，保留]
// ;[
//     `/basic/lib/jn-ve-global/style.css`,
//     `/basic/lib/jn-ve-global/fonts/iconfont.css`,
//     `/basic/css/app.${window['__BASIC_VERSION__']}.css`,
//     `/basic/css/chunk-vendors.${window['__BASIC_VERSION__']}.css`
// ].forEach((path) => {
//     loadCss(path, window['__MAIN_HOST_PATH__'])
// })

const app = createApp(App)
// 第三方容器
app.config.globalProperties.mittBus = mitt()
// 实例挂载
app.use(ElementPlus, { locale })
    .use(router)
    .use(api)
    .use<VeGlobalSetting>(GlobalComponents, VE_GLOBAL_CONFIG)
    .use<any>(LGlobalComponents)
    .use(store, key)
    .use(directives)

// 等待微应用初始化完毕（如：注入拦截器），再挂载应用
microInit({
    onInitialized() {
        app.mount('#app')
    }
})
